#coding=utf-8
import sys

wage = 0 #初始化用户薪资

#商品列表 & 价格列表
item_list = ['apple', 'banana', 'pineapple', 'watermelon', 'iphone']
price_list = [10, 20, 30, 35, 5000]

salary = int(raw_input('please input your salary here：')) #提示用户输入
print 'you salary is %s, it is so high' % salary

remain = salary #剩余价格
bought_list = [] #购物车列表

while True:
    len_item = len(item_list)   #取出物品列表中的对应的位置
    print '=============shopping list============'
    #取出物品和价格的一一对应关系并打印
    for i in range(len_item):
        print 'item %s, price %s' % (item_list[i], price_list[i])
    print '======================================'

    item = raw_input('which one do you want to buy?').strip()

    #物品不在购物列表中的时候重新进行循环
    if item not in item_list:
        print 'item not find %s, we have such items %s' % (item, item_list)
        continue
    index_item = item_list.index(item)  #取出购买物品序列
    price = price_list[index_item]  #取出购买物品对应的价格
    print 'you want %s price %s' % (item, price)

    #计算购买之后的工资剩余
    remain = remain - price

    #只有剩余工资大于0，才可以继续购买，小于0的时候
    if remain >= 0:
        bought_list.append(item)
        print 'your remaining is %s, and your bought list is %s' %(remain, bought_list)
        continue_buy = raw_input('press ok to continue buy, else exit').strip()

        #用户输入OK，继续，否则退出
        if continue_buy == 'ok':
            continue
        else:
            break
    else:
        remain = remain + price #计算不足的时候差多少钱
	print 'your remaining %s is less than price %s' % (remain, price)
        continue_buy = raw_input('press ok to continue buy, else exit').strip() #用户继续输入

        #只有输入OK，才继续，否则直接退出循环
        if continue_buy == 'ok':
            continue
        else:
            break
    break
print 'your remaining is %s, and your bought list is %s' % (remain, bought_list) #打印剩余工资和购物列表

print '==========summary================\nyou have bought'  #打印购买清单

#将购物清单内容按照一一对照价格列表进行取出价格，打印剩余工资
for item in item_list:
    if item in bought_list:
        count_item = bought_list.count(item)
        print 'item %s count %s' % (item, count_item)
print 'your remaining is %s, wage is %s' % (remain, wage)
